// 引入axios
import request from "@/utils/request"
import type { AttrInfoModel, AttrValueInfoModel } from "./model/attrModel"
import type { CategoryIdsModel } from "./model/categoryModel"
// 使用枚举
enum Api {
  getAttrListApi = "/admin/product/attrInfoList",
  delAttrListApi = "/admin/product/deleteAttr",
  addOrUpdateAttrApi = "/admin/product/saveAttrInfo",
}

// 接口
// 获取分类数据
export const reqGetAttrListDataByCategory3Id = ({
  category1Id,
  category2Id,
  category3Id,
}: CategoryIdsModel) => {
  return request.get<any, AttrValueInfoModel>(
    `${Api.getAttrListApi}/${category1Id}/${category2Id}/${category3Id}`
  )
}

// 删除属性数据
export const delAttrListData = (attrId: number) => {
  return request.delete<any, null>(`${Api.delAttrListApi}/${attrId}`)
}

// 添加属性
/**
 * 封装了一个添加或更新属性的接口函数
 * @param attrInfo
 * @returns
 */
export const reqAddOrUpdateAttrInfo = (attrInfo: AttrInfoModel) => {
  return request.post<any, null>(Api.addOrUpdateAttrApi, attrInfo)
}
